<?php
	// Représentation Objet d'un fichier disque
	// Auteur : Sebastian Mosser
	
class File {
	
	private $_path;
	private $_res;
	private $_mode;
	
	const READ   = 0;
	const WRITE  = 1;
	const APPEND = 2;
	
	public function __construct($p) { 
		$this->_path = $p; 
		$this->_res = -1;
	}

	public function open($mode) { 
		$realMode = "";
		switch ($mode) {
			case self::READ:
				$realMode = "r";
				break;
			case self::WRITE:
				$realMode = "w";
				break;
			case self::APPEND:
				$realMode = "a";
				break;
		}
		$this->_res = fopen($this->_path,$realMode);
	}
	
	public function close() {
		if ($this->_res != -1) {
			fclose($this->_res);
			$this->_res = -1;
		}
	}
	
	public function delete() {
		if ($this->_res != -1)
			$this->close();
		unlink($this->_path);
	}
	
	
	public function readLine() {
		if ($this->_res != -1)
			return fgets($this->_res);
	}
	
	public function writeLine($string) {
		if ($this->_res != -1)
			return fwrite($this->_res,$string."\n");
	}
	
	public function write($string) {
		if ($this->_res != -1)
			return fwrite($this->_res,$string);
	}
	
	public function readAll() {
		return file_get_contents($this->_path);
	}

}

?>